using System.Web.UI;
using System.Web.UI.WebControls;

namespace CommonLibrary.WebControls
{
	[ToolboxData("<{0}:SlTextBox runat=\"server\" id=\"SlTextBox1\" />")]
	public class SelfLabelTextbox : TextBox
	{
		#region Private Fields

		private string _labelText;

		#endregion

		#region Public Properties

		/// <summary>
		/// The text to display as the internal label
		/// </summary>
		public string LabelText
		{
			get { return _labelText; }
			set { _labelText = value; }
		}

		#endregion

		#region Event Handlers

		protected override void Render(HtmlTextWriter writer)
		{
			if (Text == string.Empty)
			{
				Text = LabelText;
			}

			base.Render(writer);
		}

		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
			writer.AddAttribute("onfocus", string.Format("if (this.value == '{0}') this.value = '';", LabelText));
			writer.AddAttribute("onblue", string.Format("if (this.value == '') this.value = '{0}';", LabelText));
			
			base.AddAttributesToRender(writer);
		}

		#endregion
	}
}